import 'package:get/get.dart';
import 'package:whale/helper/global/user/logic.dart';
import 'package:whale/helper/route/routes.dart';
import 'package:whale/pages/im/util/im_global.dart';
import 'package:whale/pages/im/model/im_list.dart';
import 'package:whale/pages/im/model/user.dart';

import 'index.dart';

class ImListController extends GetxController {
  ImListController();

  final state = ImListState();

  void setupData() {
    Map<String, dynamic> toJson = {
      'id': '0000',
      'name': '企明星',
      'avater': 'https://www.topnet.net.cn/img/index2/tuandui/1.png',
    };
    IMGlobal.instanse.user = ImUserModel.fromJson(toJson);
    state.list = [
      ImListModel(id: '1', fromJson: {
        'id': '0001',
        'name': '张老师',
        'avater':
            'https://bdn.135editor.com/files/users/424/4249436/201811/vfYcVsHp_nWXN.png',
      }, msgJson: {
        'id': '00001',
        'type': 'text',
        'content': '请汇报今天的工作进度',
        'time': '15:50',
        'isRemind': '1',
        'isRead': '0',
        'userId': '0001',
      }),
      ImListModel(id: '2', fromJson: {
        'id': '0002',
        'name': '马老师',
        'avater':
            'https://img2.baidu.com/it/u=3291382342,3879942314&fm=253&fmt=auto&app=138&f=JPEG?w=475&h=448',
      }, msgJson: {
        'id': '00002',
        'type': 'image',
        'content':
            'https://img95.699pic.com/xsj/04/hd/mn.jpg%21/fw/700/watermark/url/L3hzai93YXRlcl9kZXRhaWwyLnBuZw/align/southeast',
        'time': '15:48',
        'isRemind': '0',
        'isRead': '0',
        'userId': '0002',
      }),
    ];
  }

  void actionCell(ImListModel md) {
    md.msg.isRead = true;
    Get.toNamed(RouterPath.im, arguments: md);
  }

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
    setupData();
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
  }
}
